<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('货损与其他费用列表')"/>
</head>
<style>
    .table-striped table thead tr th {
        border: 1px solid #ccc !important;
    }
</style>
<body>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li class="select-time">
                            <label style="width: auto;">出入库时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginXiadanriqi]"
                                   th:value="${session.startTime}"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endXiadanriqi]"
                                   th:value="${session.endTime}"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="select-table">
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.modal.open('新增','/tongji/qita/add',1000,800)">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary" onclick="checkEdit()">
                    <i class="fa fa-edit"></i> 单个勾选修改
                </a>
                <a class="btn btn-danger" onclick="checksRemove()">
                    <i class="fa fa-remove"></i> 勾选批量删除
                </a>
                <!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="jinchuguanli:chuku:export">-->
                <!--                <i class="fa fa-download"></i> 导出-->
                <!--            </a>-->
            </div>
        </div>
        <div class="col-md-12" style="display: flex;overflow-x: scroll">
            <div class="col-sm-6 select-table table-striped">
                <table id="type1" class="table table-bordered"></table>
            </div>
            <div class="col-sm-6 select-table table-striped">
                <table id="type2" class="table table-bordered"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var prefix = ctx + "tongji/jiecun";
    $(function () {
        var options = {
            id: "type2",
            url: ctx + "tongji/qita/listGet/2",
            showToggle: false,
            showColumns: false,
            showSearch: false,
            pageSize: 100,
            toolbar: "toolbar1",
            columns: [
                [
                    {
                        checkbox: true
                    },
                    {
                        field: 'id',
                        title: 'id主键',
                        visible: false
                    },
                    {
                        field: 'fahuoren',
                        title: '费用申请人',
                        align: "center"
                    },
                    {
                        field: 'beizhu',
                        title: '费用备注',
                        align: "center"
                    },
                    {
                        field: 'leixing',
                        title: '费用类型',
                        align: "center"
                    },
                    {
                        field: 'zongjine',
                        title: '费用金额',
                        align: "center"
                    },
                    {
                        field: 'dateFor',
                        align: "center",
                        title: '费用申请日期'
                    }
                ]
            ]
        };
        var options1 = {
            id: "type1",
            url: ctx + "tongji/qita/listGet/1",
            showToggle: false,
            showColumns: false,
            showSearch: false,
            pageSize: 100,
            columns: [
                [
                    {
                        checkbox: true,
                        colspan: 1,
                        rowspan: 2
                    },
                    {
                        field: 'id',
                        title: 'id主键',
                        colspan: 1,
                        rowspan: 2,
                        visible: false
                    },
                    {
                        field: 'beizhu',
                        title: '备注',
                        align: "center",
                        colspan: 1,
                        rowspan: 2
                    },
                    {
                        field: 'zongjine',
                        title: '总金额',
                        align: "center",
                        colspan: 1,
                        rowspan: 2
                    },
                    {
                        field: 'dateFor',
                        title: '添加时间',
                        align: "center",
                        colspan: 1,
                        rowspan: 2
                    },
                    {
                        align: "center",
                        title: '货损详情',
                        colspan: 5,
                        rowspan: 1
                    }
                ],
                [
                    {
                        field: 'shangpinList',
                        align: "center",
                        title: '商品名称',
                        colspan: 1,
                        rowspan: 1,
                        formatter: function (value, row, index) {
                            var actions = [];
                            var list = ""
                            for (let i = 0; i < value.length; i++) {
                                if (i !== value.length - 1) {
                                    list += (value[i].shangpinming + "<br>")
                                } else {
                                    list += (value[i].shangpinming)
                                }
                            }
                            actions.push(list)
                            return actions.join('');
                        }
                    },
                    {
                        field: 'shangpinList',
                        align: "center",
                        title: '生产厂商',
                        colspan: 1,
                        rowspan: 1,
                        formatter: function (value, row, index) {
                            var actions = [];
                            var list = ""
                            for (let i = 0; i < value.length; i++) {
                                if (i !== value.length - 1) {
                                    list += (value[i].shengchanchangshang + "<br>")
                                } else {
                                    list += (value[i].shengchanchangshang)
                                }
                            }
                            actions.push(list)
                            return actions.join('');
                        }
                    },
                    {
                        field: 'shangpinList',
                        align: "center",
                        title: '商品类别',
                        colspan: 1,
                        rowspan: 1,
                        formatter: function (value, row, index) {
                            var actions = [];
                            var list = ""
                            for (let i = 0; i < value.length; i++) {
                                if (i !== value.length - 1) {
                                    list += (value[i].shangpinleibie + "<br>")
                                } else {
                                    list += (value[i].shangpinleibie)
                                }
                            }
                            actions.push(list)
                            return actions.join('');
                        }
                    },
                    {
                        field: 'shangpinList',
                        align: "center",
                        title: '商品售价',
                        colspan: 1,
                        rowspan: 1,
                        formatter: function (value, row, index) {
                            var actions = [];
                            var list = ""
                            for (let i = 0; i < value.length; i++) {
                                if (i !== value.length - 1) {
                                    list += (value[i].shangpinshoujia + "<br>")
                                } else {
                                    list += (value[i].shangpinshoujia)
                                }
                            }
                            actions.push(list)
                            return actions.join('');
                        }
                    },
                    {
                        field: 'shangpinList',
                        align: "center",
                        title: '货损数量',
                        colspan: 1,
                        rowspan: 1,
                        formatter: function (value, row, index) {
                            var actions = [];
                            var list = ""
                            for (let i = 0; i < value.length; i++) {
                                if (i !== value.length - 1) {
                                    list += (value[i].shangpinshuliang + "<br>")
                                } else {
                                    list += (value[i].shangpinshuliang)
                                }
                            }
                            actions.push(list)
                            return actions.join('');
                        }
                    }
                ]
            ]
        };
        $.table.init(options);
        $.table.init(options1);
    });

    function checkEdit() {
        var ids1 = $('#type1').bootstrapTable('getSelections');
        var ids2 = $('#type2').bootstrapTable('getSelections');
        if (ids1.length > 1 || ids2.length > 1 || (ids1.length >= 1 && ids2.length >= 1)){
            $.modal.alertWarning("请只选择一条记录");
            return
        }
        if (ids1.length == 1){
            $.modal.open("修改货损记录", "/tongji/qita/edit/"+ids1[0].id,1000,800);
            sessionStorage.setItem("tabBarTYPE","1")
            return;
        }
        if (ids2.length == 1){
            $.modal.open("修改其他费用记录", "/tongji/qita/edit/"+ids2[0].id,1000,800);
            sessionStorage.setItem("tabBarTYPE","2")
        }
    }

    function checksRemove() {
        var ids1 = $('#type1').bootstrapTable('getSelections');
        var ids2 = $('#type2').bootstrapTable('getSelections');
        if (ids1.length < 1 && ids2.length < 1) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var len = ids1.length+ids2.length
        var rows = []
        for (let i = 0; i < ids1.length; i++) {
            rows.push(ids1[i].id)
        }
        for (let i = 0; i < ids2.length; i++) {
            rows.push(ids2[i].id)
        }
        $.modal.confirm("确认要删除选中的" + len + "条数据吗?", function () {
            var url = ctx+"tongji/qita/removeSave";
            var data = {"ids": rows.join()};
            console.log(data)
            $.operate.submit(url, "post", "json", data);
        });
    }
</script>
</body>
</html>